package com.example.castday1.test;

import com.example.castday1.bean.UserA;
import com.example.castday1.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author : 徐闯 mpcast
 * @Date : 2021-05-22 21:05:09
 * @Description : 测试查询
 **/
@RunWith(SpringRunner.class)
@SpringBootTest
public class B_TestQuery {
    @Autowired
    private UserMapper userMapper;
    @Test
    // 根据id查询
    public void queryById(){
        UserA user = userMapper.selectById(1001);
        System.out.println(user);
    }
    @Test
    // 批量查询
    public void queryByIds(){
        List<Integer> ls = new ArrayList();
        ls.add(1001);
        ls.add(1002);
        //SELECT id AS userId,name AS username,age,email FROM User WHERE id IN ( ? , ? )
        List<UserA> userLs = userMapper.selectBatchIds(ls);
        userLs.forEach(System.out::println);
    }
    // 查询条件中存在非主键列
    @Test
    public void  queryByOtherFields(){
        Map<String,Object> map = new HashMap();
        map.put("name","zs");
        map.put("age",19);
        // 根据 名字 和 年龄进行查询
        List<UserA> list = userMapper.selectByMap(map);
        list.forEach(System.out::println);
    }
}
